﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net;
using System.IO;

namespace Web4Comment
{
    public partial class newsContent : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Response.Redirect("www.baidu.com");
            //Label1.Text = GetPage("http://www.baidu.com", Encoding.GetEncoding("GB2312"));
            //Literal1.Text = GetPage("http://www.baidu.com", Encoding.GetEncoding("GB2312"));
            string str = newsContentIframe.Attributes["src"];
            newsContentIframe.Attributes["src"] = "http://www.baidu.com";
            string str2 = newsContentIframe.Attributes["src"];
        }

        public static string GetPage(string url, Encoding encoding)
        {
            HttpWebRequest request = null;
            HttpWebResponse response = null;
            StreamReader reader = null;
            try
            {
                request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "Get";
                //request.UserAgent = "www.svnhost.cn";
                request.Timeout = 20000;
                request.AllowAutoRedirect = false;
                response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK && response.ContentLength < 1024 * 1024)
                {
                    reader = new StreamReader(response.GetResponseStream(), encoding);
                    string html = reader.ReadToEnd();
                    return html;
                }
            }
            catch
            {
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                    response = null;
                }
                if (reader != null)
                    reader.Close();
                if (request != null)
                    request = null;
            }
            return string.Empty;
        }
    }
}